package com.iias.common.domain;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

/**
 * 元组数据
 */
public class Tuple implements Serializable{

    private List<Object> objects = new ArrayList<>();

    public Tuple(Object... objects) {
        for (Object object : objects) {
            this.objects.add(object);
        }
    }

    public void add(Object obj){
        this.objects.add(obj);
    }

    /**
     * 获取第几个数据
     * @param index
     * @return
     */
    public <T> T getIndex(int index){
        return (T) objects.get(index);
    }

    public void setIndex(int index,Object obj){
        objects.set(index,obj);
    }

    public void clean(){
        objects.clear();
    }

    public List<Tuple> tuples(){
        List<Tuple> tupleList = new ArrayList<Tuple>();
        tupleList.add(this);
        return tupleList;
    }

    public static List<Tuple> addTuple(Tuple ... tuples){
        List<Tuple> tupleList = new ArrayList<Tuple>();
        for (Tuple tuple : tuples) {
            tupleList.add(tuple);
        }
        return tupleList;
    }
}
